package com.atguigu.ssyx.product.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.Attr;
import com.atguigu.ssyx.product.service.AttrService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品属性 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2025-10-30
 */
@Api(tags = "平台属性分组列表")
@RestController
@RequestMapping("/admin/product/attr")
public class AttrController {

    @Resource
    private AttrService attrService;

    // 根据平台属性分组id查询
    @ApiOperation("根据平台属性分组id查询")
    @GetMapping("{groupId}")
    public Result findAttrByGroupId(@PathVariable Long groupId) {
        List<Attr> list = attrService.findAttrByGroupId(groupId);
        return Result.ok(list);
    }

    // 根据id查询属性列表
    @ApiOperation("根据id查询属性列表")
    @GetMapping("get/{id}")
    public Result get(@PathVariable Long id) {
        Attr attr = attrService.getById(id);
        return Result.ok(attr);
    }

    // 添加属性
    @ApiOperation("添加属性")
    @PostMapping("save")
    public Result save(Attr attr) {
        boolean save = attrService.save(attr);
        return Result.ok(save);
    }

    // 修改属性
    @ApiOperation("修改属性")
    @PutMapping("update")
    public Result update(@RequestBody Attr attr) {
        boolean update = attrService.updateById(attr);
        return Result.ok(update);
    }

    // 删除属性
    @ApiOperation("删除属性")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        boolean remove = attrService.removeById(id);
        return Result.ok(remove);
    }

    // 批量删除属性
    @ApiOperation("批量删除属性")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        boolean remove = attrService.removeByIds(idList);
        return Result.ok(remove);
    }
}

